﻿
@{
    Layout = null;
}

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="shortcut icon" href="./favicon.ico" type="image/x-icon" />
    <link href="~/Scripts/layui/css/layui.css" rel="stylesheet" />
    <link href="~/Content/login.css" rel="stylesheet" />
</head>
<body class="login-bg">

    <div class="login-box">
        <form action="" method="post" class="layui-form layui-form-pane">
            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                <legend>登录</legend>
            </fieldset>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    用户名
                </label>
                <div class="layui-input-inline layui-input-big-width">
                    <input type="text" name="username" lay-verify="required" autocomplete="off" placeholder="请输入用户名"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    密码
                </label>
                <div class="layui-input-inline layui-input-big-width">
                    <input type="password" name="password" lay-verify="required" placeholder="请输入密码"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    验证码
                </label>
                <div class="layui-input-inline layui-input-small-width ">
                    <input type="text" name="checkCode" lay-verify="required" placeholder="验证码" autocomplete="off"
                           class="layui-input">
                </div>
                <div class="layui-input-inline layui-input-code-width">
                    <img src='@Url.Action("GetCheckCode")' id="imgCheckCode" class="layui-input" title="点击更改验证码" />
                </div>
            </div>
            <button class="layui-btn" lay-submit="" id="btnSub" lay-filter="btnSub" type="button">
                登录
            </button>
        </form>
        <div class="copyright">
            © 2017-2018 LFDCC All Rights Reserved.
        </div>
    </div>
    <script src="~/Scripts/layui/layui.js"></script>
    <script type="text/javascript">

        layui.use(['form','layer'], function () {
            var form = layui.form;
            var layer = layui.layer;
            var $ = layui.$;
            var index = 0;
            //监听提交
            form.on('submit(btnSub)', function (data) {
                $.ajax({
                    url:'/Account/Login',
                    type: "post",
                    dataType: "json",
                    data: data.field,
                    beforeSend: function () {
                        layer.msg('登陆中...', {
                            icon: 16
                            , shade: 0.2
                            , time:0
                        });
                    },
                    success: function (res) {
                        if (res.status == 200) {
                            location.replace("/Home/Index/" + new Date().getTime());
                        } else {
                            layer.closeAll();
                            index = layer.alert(res.msg, { icon: 5 });
                            $("#imgCheckCode").click();
                        }
                    }
                });
                return false;
            });
            //自定义验证规则
            form.verify({
                username: function (value) {
                    if (value.length == 0) {
                        return '请输入用户名！';
                    }
                }
                , password: function (value) {
                    if (value.length == 0) {
                        return '请输入密码！';
                    }
                }, verifycode: function (value) {
                    if (value.length == 0) {
                        return '请输入验证码！';
                    }
                }
            });

            $("#imgCheckCode").on("click", function () {
                $(this).attr('src', '@Url.Action("GetCheckCode")/' + new Date().getTime());
            })
            $(document).on("keydown", function (event) {
                if (event.keyCode == 13) {
                    if ($("#layui-layer" + index).length==1) {
                        layer.close(index);
                    } else {
                        $("#btnSub").click();
                    }
                }
            })
        });
    </script>
    <!-- 底部结束 -->
</body>
</html>

